package makabakaquestionnaire.zutsoftware.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import makabakaquestionnaire.zutsoftware.entity.request.QueryProjectRequest;
import makabakaquestionnaire.zutsoftware.entity.UserProject;
import makabakaquestionnaire.zutsoftware.mapper.UserProjectMapper;
import makabakaquestionnaire.zutsoftware.service.UserProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserProjectServiceImpl implements UserProjectService {

    private UserProjectMapper userProjectMapper;
    @Autowired
    public void setUserProjectMapper(UserProjectMapper userProjectMapper) {
        this.userProjectMapper = userProjectMapper;
    }

    @Override
    public List<UserProject> queryAll() {
        return userProjectMapper.queryAll();
    }

    @Override
    public UserProject queryProjectByProKey(String proKey) {
        return userProjectMapper.queryProjectByProKey(proKey);
    }


    @Override
    public List<UserProject> queryProjectWithStatus(Long Status,String username){
        return userProjectMapper.queryProjectWithStatus(Status,username);
    }

    @Override
    public List<UserProject> queryProjectByUserID(Long UserID) {
        return userProjectMapper.queryProjectByUserID(UserID);
    }


    @Override
    public Boolean insertProject(UserProject userProject) {
        int n=userProjectMapper.insertProject(userProject);
        if (n!=1){
            return false;
        }else {
            return true;
        }

    }

    @Override
    public Boolean updateProject(UserProject userProject) {
      int n=userProjectMapper.updateProject(userProject);
        if (n!=1){
            return false;
        }else {
            return true;
        }

    }


    @Override
    public Boolean deleteProject(Long id) {
        return null;
    }

    @Override
    public PageInfo<UserProject> queryProjectByRequest(QueryProjectRequest queryProjectRequest) {
        PageHelper.startPage(queryProjectRequest.getPageNum(),queryProjectRequest.getPageSize());
        List<UserProject> userProjects= userProjectMapper.queryProjectByRequest(queryProjectRequest);
        return new PageInfo<UserProject>(userProjects);
    }

    //get请求
    public PageInfo<UserProject> queryProjectByRequest(Long status,  String username) {
        PageHelper.startPage(1,10);
        List<UserProject> userProjects= userProjectMapper.queryProjectWithStatus(status,  username);
        return new PageInfo<UserProject>(userProjects);
    }


}
